//
//  CZBindMoblieViewController.m
//  nsj_iOS
//
//  Created by apple on 2017/1/16.
//  Copyright © 2017年 GCZ. All rights reserved.
//

#import "CZBindMoblieViewController.h"
#import "CZVerificationBtn.h"
@interface CZBindMoblieViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *bindMoblieTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;
@property (weak, nonatomic) IBOutlet CZVerificationBtn *codeBtn;

@end

@implementation CZBindMoblieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"绑定手机";
    _codeBtn.delgate = self;
    _codeBtn.phoneNumber = @"";
    _bindMoblieTF.delegate = self;
    // Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.alpha = 1;
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    _codeBtn.phoneNumber = textField.text;
}
- (IBAction)confirmAction:(UIButton *)sender {
    NSString *urlString = [NSString stringWithFormat:@"%@/api/web/index.php/v1/user/bind-phone",APP_HOST];
    if (_bindMoblieTF.text.length != 11) {
        [SVProgressHUD showErrorWithStatus:@"请输入正确的手机号"];
        return;
    }
    if (_codeTF.text.length < 2) {
        [SVProgressHUD showErrorWithStatus:@"请输入正确的验证码"]
        ;
        return;
    }
    [GCZAFNetWorking POST:urlString params:@{@"phone" : _bindMoblieTF.text, @"code" : _codeTF.text, @"token" : [[NSUserDefaults standardUserDefaults] objectForKey:User_Token]} success:^(NSDictionary *response) {
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
